import enum


@enum.unique
class BaseCodeEnum(enum.Enum):
    def __init__(self, code, desc: str):
        """基础枚举类 初始化

        :param code: 编码值
        :param desc: 字段描述
        """
        self._code = code
        self._desc = desc

    @property
    def code(self):
        """编码值"""
        return self._code

    @property
    def desc(self):
        """字段描述"""
        return self._desc

    @classmethod
    def get_enum(cls, code):
        """根据code获取enum"""
        for e in cls.__members__.values():
            if e.code == code:
                return e
        return None

    @classmethod
    def get_desc(cls, code):
        """根据code获取字段描述"""
        for e in cls.__members__.values():
            if e.code == code:
                return e.desc
        return ""

    @classmethod
    def get_choices(cls):
        """获取选择项 ((k, v), (k2, v2))"""
        return tuple(e.value for e in cls.__members__.values())
